package com.huijie.app.configuration;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.exceptions.JedisConnectionException;

/** 
* @ClassName: RedisConfiguration
* @Description: TODO
* @author lenovo
* @date 2018年7月24日 上午11:19:18
*  
*/
@Configuration
public class RedisConfiguration {

    // 短信验证码过期时间key
    public static final String CAPTCHA = "_captcha-william" ;

    // 短信验证码过期时间key
    public static final String TOKEN = "_token-william" ;

    // 分割符
    public static final String CUT = "_" ;


    @Value("${spring.redis.host}")
    private String host;
    @Value("${spring.redis.port}")
    private int port;
    @Value("${spring.redis.password}")
    private String password;
    @Value("${spring.redis.timeout}")
    private int timeout;
    @Value("${spring.redis.pool.max-active}")
    private int maxActive;
    @Value("${spring.redis.pool.max-idle}")
    private int maxIdle;
    @Value("${spring.redis.pool.min-idle}")
    private int minIdle;
    @Value("${spring.redis.pool.max-wait}")
    private int maxWait;
    
    private static JedisPool pool = null;
 
    @Bean
    public JedisPool jedisConnectionFactory() {
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(maxActive);
        jedisPoolConfig.setMaxIdle(maxIdle);
        jedisPoolConfig.setMinIdle(minIdle);
        jedisPoolConfig.setMaxWaitMillis(maxWait);
        pool = new JedisPool(jedisPoolConfig, host, port, timeout);
//        pool = new JedisPool(jedisPoolConfig,host,port,timeout,password);
        try {
            pool.getResource();
        }catch(JedisConnectionException e) {
           e.printStackTrace();
        }
        return pool;
    }
    
}

